﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Components.UserControls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Threading;
using System.Windows.Threading;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{

    public partial class ViewBase
    {
        public delegate void LOADBYAUFDelegate();
        public delegate void EXAUFDelegate(string str);
        public delegate void BOOLDelegate(bool str);
        public Task LOADBYAUFTask;
        public Task EXAUFTask;
        public Task NormalTask;
        public Task WFNEWTask;
        public delegate void PMDelegate(Dictionary<string, object> pm);
        public delegate void WFCHGDelegate(Dictionary<string, object> pm);
        public ITXConnectInfo itxclient
        {
            get
            {
                return app.itxclient;
            }
        }

        #region ==ORDERNUM===========
        public static readonly DependencyProperty ORDERNUMProperty = DependencyProperty.Register("ORDERNUM",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnORDERNUMChanged));
        public string ORDERNUM
        {
            get
            {
                return (string)GetValue(ORDERNUMProperty);
            }
            set
            {
                SetValue(ORDERNUMProperty, value);
                if (MV == null) return;

                if (MV.ORDERNUM != value)
                {
                    MV.ORDERNUM = value; 
                    // LOADBYAUFTask = Task.Factory.StartNew(() => LOADBYAUF(), new CancellationTokenSource().Token, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
                    // LOADBYAUFTask.Wait();
                } 
            }
        }
        private static void OnORDERNUMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.ORDERNUM = (string)e.NewValue;
                src.LOADBYAUF();
            }
        }

        public virtual void LOADBYAUF()
        {

        }

        #endregion 
        
        #region ==EXAUF===========

        public static readonly DependencyProperty EXAUFProperty = DependencyProperty.Register("EXAUF",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnEXAUFChanged));
        public string EXAUF
        {
            get
            {
                return (string)GetValue(EXAUFProperty);
            }
            set
            {
                SetValue(EXAUFProperty, value);
             
                //    EXAUFTask = Task.Factory.StartNew(() => OnEXAUFChg(value), new CancellationTokenSource().Token, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }

        private static void OnEXAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.EXAUF = (string)e.NewValue;
                src.OnEXAUFChg((string)e.NewValue);
            }
        }

        public virtual void OnEXAUFChg(string value)
        {
            if (MV == null)
                return;
            MV.EXAUF = value; 
        }

        #endregion
      
        #region ==QTY===========
        public static readonly DependencyProperty QTYProperty = DependencyProperty.Register("QTY",
        typeof(double), typeof(ViewBase),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnQTYChanged));
        public double QTY
        {
            get
            {
                return (double)GetValue(QTYProperty);
            }
            set
            {
                SetValue(QTYProperty, value);
            }
        }
        private static void OnQTYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.QTY = (double)e.NewValue;
            }
        }
        public virtual void OnQTYChg(double value)
        {
        }
        #endregion 

        #region ==QTYP===========
        public static readonly DependencyProperty QTYPProperty = DependencyProperty.Register("QTYP",
        typeof(string), typeof(ViewBase),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnQTYPChanged));
        public string QTYP
        {
            get
            {
                return (string)GetValue(QTYPProperty);
            }
            set
            {
                SetValue(QTYPProperty, value);
            }
        }
        private static void OnQTYPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.QTYP = (string)e.NewValue;
            }
        }
        public virtual void OnQTYPChg(string value)
        {
        }
        #endregion

        #region ==EXPM===========
        public static readonly DependencyProperty EXPMProperty = DependencyProperty.Register("EXPM",
        typeof(Dictionary<string,object>), typeof(ViewBase),
        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnEXPMChanged));
        public Dictionary<string, object> EXPM
        {
            get
            {
                return (Dictionary<string, object>)GetValue(EXPMProperty);
            }
            set
            {
                SetValue(EXPMProperty, value);
            }
        }
        private static void OnEXPMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.EXPM = (Dictionary<string, object>)e.NewValue;
            }
        } 
        #endregion

        #region ==ENVPM===========
        public static readonly DependencyProperty ENVPMProperty = DependencyProperty.Register("ENVPM",
        typeof(Dictionary<string, object>), typeof(ViewBase),
        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnENVPMChanged));
        public Dictionary<string, object> ENVPM
        {
            get
            {
                return (Dictionary<string, object>)GetValue(ENVPMProperty);
            }
            set
            {
                SetValue(ENVPMProperty, value);
                OnENVPMChg(value);
            }
        }
        private static void OnENVPMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.ENVPM = (Dictionary<string, object>)e.NewValue;
            }
        } 
        public virtual void OnENVPMChg(Dictionary<string, object> ennpm)
        {
             
        }
        #endregion

        #region ==SHIFT===========
        public static readonly DependencyProperty SHIFTProperty = DependencyProperty.Register("SHIFT",
        typeof(string), typeof(ViewBase),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSHIFTChanged));
        public string SHIFT
        {
            get
            {
                return (string)GetValue(SHIFTProperty);
            }
            set
            {
                SetValue(SHIFTProperty, value);
                OnSHIFTChg(value);
            }
        }
        private static void OnSHIFTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.SHIFT = (string)e.NewValue;
            }
        }
        public virtual void OnSHIFTChg(string value)
        {
        }
        #endregion

        #region ==IsExpandAll===========
        public static readonly DependencyProperty IsExpandAllProperty = DependencyProperty.Register("IsExpandAll",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsExpandAllChanged));
        public bool IsExpandAll
        {
            get
            {
                return (bool)GetValue(IsExpandAllProperty);
            }
            set
            {
                SetValue(IsExpandAllProperty, value); 
            }
        }
        private static void OnIsExpandAllChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsExpandAll = (bool)e.NewValue;
            }
        } 
        #endregion

        #region ==IsMaster===========
        public static readonly DependencyProperty IsMasterProperty = DependencyProperty.Register("IsMaster",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsMasterChanged));
        public bool IsMaster
        {
            get
            {
                return (bool)GetValue(IsMasterProperty);
            }
            set
            {
                SetValue(IsMasterProperty, value);
               
            }
        }
        private static void OnIsMasterChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsMaster = (bool)e.NewValue;
                src.OnMasterChg((bool)e.NewValue);
            }
        }
        public virtual void OnMasterChg(bool value)
        {
            if (MV == null)
                return;
            MV.IsMaster = value;
        }
        #endregion

     

        #region ==IsQuery===========
        public static readonly DependencyProperty IsQueryProperty = DependencyProperty.Register("IsQuery",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsQueryChanged));
        public bool IsQuery
        {
            get
            {
                return (bool)GetValue(IsQueryProperty);
            }
            set
            {
                SetValue(IsQueryProperty, value); 
            }
        }
        private static void OnIsQueryChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsQuery = (bool)e.NewValue;
                src.OnQueryChg((bool)e.NewValue);
            }
        }
        public virtual void OnQueryChg(bool value)
        {
        }
        #endregion

        #region ==IsInactive===========
        public static readonly DependencyProperty IsInactiveProperty = DependencyProperty.Register("IsInactive",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsInactiveChanged));
        public bool IsInactive
        {
            get
            {
                return (bool)GetValue(IsInactiveProperty);
            }
            set
            {
                SetValue(IsInactiveProperty, value);
            }
        }
        private static void OnIsInactiveChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsInactive = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCanInactive===========
        public static readonly DependencyProperty IsCanInactiveProperty = DependencyProperty.Register("IsCanInactive",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCanInactiveChanged));
        public bool IsCanInactive
        {
            get
            {
                return (bool)GetValue(IsCanInactiveProperty);
            }
            set
            {
                SetValue(IsCanInactiveProperty, value);
            }
        }
        private static void OnIsCanInactiveChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsCanInactive = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCanDelete===========
        public static readonly DependencyProperty IsCanDeleteProperty = DependencyProperty.Register("IsCanDelete",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCanDeleteChanged));
        public bool IsCanDelete
        {
            get
            {
                return (bool)GetValue(IsCanDeleteProperty);
            }
            set
            {
                SetValue(IsCanDeleteProperty, value);
            }
        }
        private static void OnIsCanDeleteChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsCanDelete = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCanNew===========
        public static readonly DependencyProperty IsCanNewProperty = DependencyProperty.Register("IsCanNew",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCanNewChanged));
        public bool IsCanNew
        {
            get
            {
                return (bool)GetValue(IsCanNewProperty);
            }
            set
            {
                SetValue(IsCanNewProperty, value);
            }
        }
        private static void OnIsCanNewChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsCanNew = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsBTNInfo===========
        public static readonly DependencyProperty IsBTNInfoProperty = DependencyProperty.Register("IsBTNInfo",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsBTNInfoChanged));
        public bool IsBTNInfo
        {
            get
            {
                return (bool)GetValue(IsBTNInfoProperty);
            }
            set
            {
                SetValue(IsBTNInfoProperty, value);
            }
        }
        private static void OnIsBTNInfoChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsBTNInfo = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCanChg===========
        public static readonly DependencyProperty IsCanChgProperty = DependencyProperty.Register("IsCanChg",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCanChgChanged));
        public bool IsCanChg
        {
            get
            {
                return (bool)GetValue(IsCanChgProperty);
            }
            set
            {
                SetValue(IsCanChgProperty, value);
            }
        }
        private static void OnIsCanChgChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsCanChg = (bool)e.NewValue;
            }
        }
        #endregion
        #region ==IsCopy===========
        public static readonly DependencyProperty IsCopyProperty = DependencyProperty.Register("IsCopy",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCopyChanged));
        public bool IsCopy
        {
            get
            {
                return (bool)GetValue(IsCopyProperty);
            }
            set
            {
                SetValue(IsCopyProperty, value);
            }
        }
        private static void OnIsCopyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsCopy = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCanCopy===========
        public static readonly DependencyProperty IsCanCopyProperty = DependencyProperty.Register("IsCanCopy",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCanCopyChanged));
        public bool IsCanCopy
        {
            get
            {
                return (bool)GetValue(IsCanCopyProperty);
            }
            set
            {
                SetValue(IsCanCopyProperty, value);
            }
        }
        private static void OnIsCanCopyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsCanCopy = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCanManage===========
        public static readonly DependencyProperty IsCanManageProperty = DependencyProperty.Register("IsCanManage",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCanManageChanged));
        public bool IsCanManage
        {
            get
            {
                return (bool)GetValue(IsCanManageProperty);
            }
            set
            {
                SetValue(IsCanManageProperty, value);
            }
        }
        private static void OnIsCanManageChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsCanManage = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==ScopeManage===========
        public static readonly DependencyProperty ScopeManageProperty = DependencyProperty.Register("ScopeManage",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnScopeManageChanged));
        public string ScopeManage
        {
            get
            {
                return (string)GetValue(ScopeManageProperty);
            }
            set
            {
                SetValue(ScopeManageProperty, value);
            }
        }
        private static void OnScopeManageChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.ScopeManage = (string)e.NewValue;
            }
        }
        #endregion

        public DataTable TBPRG
        {
            get
            {
                return app.TBPRG;
            }
            set
            {
                app.TBPRG = value;
            }
        }
        public DataTable TBUR
        {
            get
            {
                return app.TBUR;
            }
            set
            {
                app.TBUR = value;
            }
        }

        public Dictionary<string, DataTable> DBSDDAT
        {
            get
            {
                return app.DBSDDAT;
            }

        }
        #region ==WH===========
        public static readonly DependencyProperty WHProperty = DependencyProperty.Register("WH",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWHChanged));
        public string WH
        {
            get
            {
                return (string)GetValue(WHProperty);
            }
            set
            {
                SetValue(WHProperty, value);
                OnWHChg(value);
            }
        }
        private static void OnWHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.WH = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowGrid===========
        public static readonly DependencyProperty IsShowGridProperty = DependencyProperty.Register("IsShowGrid",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowGridChanged));
        public bool IsShowGrid
        {
            get
            {
                return (bool)GetValue(IsShowGridProperty);
            }
            set
            {
                SetValue(IsShowGridProperty, value); 
            }
        }
        private static void OnIsShowGridChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsShowGrid = (bool)e.NewValue;
            }
        }
        #endregion
        #region ==IsShowLeft===========
        public static readonly DependencyProperty IsShowLeftProperty = DependencyProperty.Register("IsShowLeft",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowLeftChanged));
        public bool IsShowLeft
        {
            get
            {
                return (bool)GetValue(IsShowLeftProperty);
            }
            set
            {
                SetValue(IsShowLeftProperty, value);
                if (father != null)
                {
                    if (father is DocumentBase)
                    {
                        ((DocumentBase)father).IsShowLeft = value;
                    }
                }
            }
        }
        private static void OnIsShowLeftChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsShowLeft = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowRight===========
        public static readonly DependencyProperty IsShowRightProperty = DependencyProperty.Register("IsShowRight",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowRightChanged));
        public bool IsShowRight
        {
            get
            {
                return (bool)GetValue(IsShowRightProperty);
            }
            set
            {
                SetValue(IsShowRightProperty, value);
                if (father != null)
                {
                    if (father is DocumentBase)
                    {
                        ((DocumentBase)father).IsShowRight = value;
                    }
                }
            }
        }
        private static void OnIsShowRightChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsShowRight = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowTop===========
        public static readonly DependencyProperty IsShowTopProperty = DependencyProperty.Register("IsShowTop",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowTopChanged));
        public bool IsShowTop
        {
            get
            {
                return (bool)GetValue(IsShowTopProperty);
            }
            set
            {
                SetValue(IsShowTopProperty, value);

                if (father != null)
                {
                    if (father is DocumentBase)
                    {
                        ((DocumentBase)father).IsShowTop = value;
                    }
                }
            }
        }
        private static void OnIsShowTopChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsShowTop = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowBottom===========
        public static readonly DependencyProperty IsShowBottomProperty = DependencyProperty.Register("IsShowBottom",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowBottomChanged));
        public bool IsShowBottom
        {
            get
            {
                return (bool)GetValue(IsShowBottomProperty);
            }
            set
            {
                SetValue(IsShowBottomProperty, value);
                if (father != null)
                {
                    if (father is DocumentBase)
                    {
                        ((DocumentBase)father).IsShowBottom = value;
                    }
                }
            }
        }
        private static void OnIsShowBottomChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsShowBottom = (bool)e.NewValue;
            }
        }
        #endregion

        #region Events

        public static readonly RoutedEvent ValueChangedEvent =
            EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble,
            typeof(RoutedPropertyChangedEventHandler<object>), typeof(ViewBase));
        public event RoutedPropertyChangedEventHandler<object> ValueChanged
        {
            add
            {
                AddHandler(ValueChangedEvent, value);
            }
            remove
            {
                RemoveHandler(ValueChangedEvent, value);
            }
        }
        public static void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ViewBase vb = sender as ViewBase;
            if (vb != null)
                vb.OnValueChanged((object)e.OldValue, (object)e.NewValue);
        }

        public virtual void OnValueChanged(object oldValue, object newValue)
        {
            RoutedPropertyChangedEventArgs<object> args = new RoutedPropertyChangedEventArgs<object>(oldValue, newValue);
            args.RoutedEvent = ValueChangedEvent;
            RaiseEvent(args);
        }
        #endregion //Events

        #region ==TBEXT===========
        public static readonly DependencyProperty TBEXTProperty = DependencyProperty.Register("TBEXT",
            typeof(DataTable), typeof(ViewBase),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnTBEXTChanged));
        public DataTable TBEXT
        {
            get
            {
                return (DataTable)GetValue(TBEXTProperty);
            }
            set
            {
                SetValue(TBEXTProperty, value);
            }
        }
        private static void OnTBEXTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.TBEXT = (DataTable)e.NewValue;
            }
        }
        #endregion
        public bool IsOneBELGE
        {
            get
            {

                if (!ENVMAIN.ContainsKey("IsOneBELGE"))
                    ENVMAIN["IsOneBELGE"] = false; 
                return (bool)ENVMAIN["IsOneBELGE"];
            }
            set
            { 
                ENVMAIN["IsOneBELGE"] = value;
            }
        }
        public ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public BackgroundWorker bgWorker;
        public string MESSAGES = "CHAGELVL;CHGMODE;CHGLANG;CHGZM;";
        public string RUNID
        {
            get
            {
                if (MV == null) return "";
                return MV.RUNID;
            }
            set
            {
                if (MV == null) return;
                MV.RUNID = value;
            }
        }
        private string _WFID; public string WFID { get { return _WFID; } set { _WFID = value; OnWorkflowIDChange(_WFID); } }
        public Dictionary<string, object> PM
        {
            get
            {
                return MV.PM;
            }
            set
            {
                MV.PM = value;
            }
        }
        public Dictionary<string, object> ENVMAIN
        {
            get
            {
                return app.ENVMAIN(app.UserIP);
            }
        }

        #region ==TXTISIND===========
        public static readonly DependencyProperty TXTISINDProperty = DependencyProperty.Register("TXTISIND",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnTXTISINDChanged));
        public string TXTISIND
        {
            get
            {
                return (string)GetValue(TXTISINDProperty);
            }
            set
            {
                SetValue(TXTISINDProperty, value);
            }
        }
        private static void OnTXTISINDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var source = sender as ViewBase;
            if (source != null)
            {
                source.TXTISIND = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsAuto===========
        public static readonly DependencyProperty IsAutoProperty = DependencyProperty.Register("IsAuto",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsAutoChanged));
        public bool IsAuto
        {
            get
            {
                return (bool)GetValue(IsAutoProperty);
            }
            set
            {
                SetValue(IsAutoProperty, value);
                OnAutoChg(value);
            }
        }
        private static void OnIsAutoChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsAuto = (bool)e.NewValue;
            }
        }

        public virtual void OnAutoChg(bool value)
        {
        }
        #endregion

        #region ==IsCanLoad===========
        public static readonly DependencyProperty IsCanLoadProperty = DependencyProperty.Register("IsCanLoad",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCanLoadChanged));
        public bool IsCanLoad
        {
            get
            {
                return (bool)GetValue(IsCanLoadProperty);
            }
            set
            {
                SetValue(IsCanLoadProperty, value);
                OnLoadChg(value);
            }
        }
        private static void OnIsCanLoadChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsCanLoad = (bool)e.NewValue;
            }
        }

        public virtual void OnLoadChg(bool value)
        {
            if (!value)
                return;
            string key = ORDERNUM;
            ORDERNUM = "";
            ORDERNUM = key;
            key = EXAUF;
            EXAUF = "";
            EXAUF = key;
        }
        #endregion

        #region ==PRTYPE===========
        public static readonly DependencyProperty PRTYPEProperty = DependencyProperty.Register("PRTYPE",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPRTYPEChanged));
        public string PRTYPE
        {
            get
            {
                return (string)GetValue(PRTYPEProperty);
            }
            set
            {
                SetValue(PRTYPEProperty, value);
            }
        }
        private static void OnPRTYPEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.PRTYPE = (string)e.NewValue;
            }
        }
        #endregion

        #region ==INFO===========
        public static readonly DependencyProperty INFOProperty = DependencyProperty.Register("INFO",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnINFOChanged));
        public string INFO
        {
            get
            {
                return (string)GetValue(INFOProperty);

            }
            set
            {
                SetValue(INFOProperty, value);
                OnINFOChg(value);
            }
        }
        private static void OnINFOChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.INFO = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IMAGEPATH===========
        public static readonly DependencyProperty IMAGEPATHProperty = DependencyProperty.Register("IMAGEPATH",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIMAGEPATHChanged));
        public string IMAGEPATH
        {
            get
            {
                return (string)GetValue(IMAGEPATHProperty);
            }
            set
            {
                SetValue(IMAGEPATHProperty, value);
            }
        }
        private static void OnIMAGEPATHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IMAGEPATH = (string)e.NewValue;
            }
        }
        #endregion

        #region ==LO===========
        public static readonly DependencyProperty LOProperty = DependencyProperty.Register("LO",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLOChanged));
        public string LO
        {
            get
            {
                return (string)GetValue(LOProperty);
            }
            set
            {
                SetValue(LOProperty, value);
                OnLOChg(value);
                if (MV == null) return;
                MV.LO = value;
            }
        }
        private static void OnLOChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.LO = (string)e.NewValue;
            }
        }
        public virtual void OnLOChg(string lo)
        { }
        #endregion

        #region ==LB===========
        public static readonly DependencyProperty LBProperty = DependencyProperty.Register("LB",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLBChanged));
        public string LB
        {
            get
            {
                return (string)GetValue(LBProperty);
            }
            set
            {
                SetValue(LBProperty, value);
                OnLBChg(value);
                if (MV == null) return;
                MV.LB = value;
            }
        }
        private static void OnLBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.LB = (string)e.NewValue;
            }
        }
        public virtual void OnLBChg(string lo)
        { }
        #endregion

        #region ==LP===========
        public static readonly DependencyProperty LPProperty = DependencyProperty.Register("LP",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLPChanged));
        public string LP
        {
            get
            {
                return (string)GetValue(LPProperty);
            }
            set
            {
                SetValue(LPProperty, value);
                OnLPChg(value);
                if (MV == null) return;
                MV.LP = value;
            }
        }
        private static void OnLPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.LP = (string)e.NewValue;
            }
        }
        public virtual void OnLPChg(string lo)
        { }
        #endregion

        #region ==DTSTART===========
        public static readonly DependencyProperty DTSTARTProperty = DependencyProperty.Register("DTSTART",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDTSTARTChanged));
        public string DTSTART
        {
            get
            {
                return (string)GetValue(DTSTARTProperty);
            }
            set
            {
                SetValue(DTSTARTProperty, value);
                OnDTSTARTChg(value);

            }
        }
        private static void OnDTSTARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.DTSTART = (string)e.NewValue;
            }
        }
        public virtual void OnDTSTARTChg(string value)
        {
            if (MV == null) return;
            MV.DTSTART = value;
        }
        #endregion

        #region ==DTEND===========
        public static readonly DependencyProperty DTENDProperty = DependencyProperty.Register("DTEND",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDTENDChanged));
        public string DTEND
        {
            get
            {
                return (string)GetValue(DTENDProperty);
            }
            set
            {
                SetValue(DTENDProperty, value);
                OnDTENDChg(value);
            }
        }
        private static void OnDTENDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.DTEND = (string)e.NewValue;
            }
        }
        public virtual void OnDTENDChg(string value)
        {
            if (MV == null) return;
            MV.DTEND = value;
        }
        #endregion

        #region ==KEY===========
        public static readonly DependencyProperty KEYProperty = DependencyProperty.Register("KEY",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKEYChanged));
        public string KEY
        {
            get
            {
                return (string)GetValue(KEYProperty);
            }
            set
            {
                SetValue(KEYProperty, value);
                if (MV == null) return;
                MV.KEY = value;
            }
        }
        private static void OnKEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.KEY = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KOLL===========
        public static readonly DependencyProperty KOLLProperty = DependencyProperty.Register("KOLL",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKOLLChanged));
        public string KOLL
        {
            get
            {
                return (string)GetValue(KOLLProperty);
            }
            set
            {
                SetValue(KOLLProperty, value);
               
            }
        }
        private static void OnKOLLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.KOLL = (string)e.NewValue;
                src.OnKOLLChg((string)e.NewValue);
            }
        }
        public virtual void OnKOLLChg(string value)
        {
            if (MV == null) return;
            MV.KOLL = value;

        }
        #endregion

        #region ==KRS===========
        public static readonly DependencyProperty KRSProperty = DependencyProperty.Register("KRS",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKRSChanged));
        public string KRS
        {
            get
            {
                return (string)GetValue(KRSProperty);
            }
            set
            {
                SetValue(KRSProperty, value);
                if (MV == null) return;
                MV.KRS = value;
                OnKRS();
            }
        }
        private static void OnKRSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.KRS = (string)e.NewValue;
            }
        }
        public virtual void OnKRS()
        {
        }
        #endregion

        #region ==LFD===========
        public static readonly DependencyProperty LFDProperty = DependencyProperty.Register("LFD",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLFDChanged));
        public string LFD
        {
            get
            {
                return (string)GetValue(LFDProperty);
            }
            set
            {
                SetValue(LFDProperty, value);
                OnLFDChg();
                if (MV == null) return;
                MV.LFD = value;
            }
        }
        private static void OnLFDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.LFD = (string)e.NewValue;
            }
        }
        public virtual void OnLFDChg()
        { }
        #endregion

        #region ==POS===========
        public static readonly DependencyProperty POSProperty = DependencyProperty.Register("POS",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPOSChanged));
        public string POS
        {
            get
            {
                return (string)GetValue(POSProperty);
            }
            set
            {
                SetValue(POSProperty, value);
                if (MV == null) return;
                MV.POS = value;
            }
        }
        private static void OnPOSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.POS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==UPOS===========
        public static readonly DependencyProperty UPOSProperty = DependencyProperty.Register("UPOS",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnUPOSChanged));
        public string UPOS
        {
            get
            {
                return (string)GetValue(UPOSProperty);
            }
            set
            {
                SetValue(UPOSProperty, value);
                if (MV == null) return;
                MV.UPOS = value;
                OnUPOS();
            }
        }
        private static void OnUPOSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.UPOS = (string)e.NewValue;
            }
        }
        public virtual void OnUPOS()
        {
        }
        #endregion

        #region ==ARTST===========
        public static readonly DependencyProperty ARTSTProperty = DependencyProperty.Register("ARTST",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnARTSTChanged));
        public string ARTST
        {
            get
            {
                return (string)GetValue(ARTSTProperty);

            }
            set
            {
                SetValue(ARTSTProperty, value);
                OnARTSTChg();

            }
        }
        private static void OnARTSTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.ARTST = (string)e.NewValue;
            }
        }
        public virtual void OnARTSTChg()
        {
            if (MV == null) return;
            MV.ARTST = ARTST;
        }
        #endregion

        #region ==IsReset===========
        public static readonly DependencyProperty IsResetProperty = DependencyProperty.Register("IsReset",
        typeof(bool), typeof(ViewBase),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsResetChanged));
        public bool IsReset
        {
            get
            {
                return (bool)GetValue(IsResetProperty);
            }
            set
            {
                SetValue(IsResetProperty, value);
              
            }
        }
        private static void OnIsResetChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsReset = (bool)e.NewValue;
                src.OnReSetChg();
            }
        }

        public virtual void OnReSetChg()
        {
            TBMain.Clear(); 
        }
        public void Reset()
        {
            if(vwMaster.View!=null)
            {
                vwMaster.View.MoveCurrentTo(-1);
            }
        }
        #endregion


        #region ==ART===========
        public static readonly DependencyProperty ARTProperty = DependencyProperty.Register("ART",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnARTChanged));
        public string ART
        {
            get
            {
                return (string)GetValue(ARTProperty);
            }
            set
            {
                SetValue(ARTProperty, value);
               
            }
        }
        private static void OnARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.ART = (string)e.NewValue;
                src.OnARTChg((string)e.NewValue);
            }
        }
        public virtual void OnARTChg(string des)
        {
            if (MV == null) return;
            MV.ART = des;
        }
        #endregion

        #region ==VAR===========
        public static readonly DependencyProperty VARProperty = DependencyProperty.Register("VAR",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVARChanged));
        public string VAR
        {
            get
            {
                return (string)GetValue(VARProperty);
            }
            set
            {
                SetValue(VARProperty, value);
              
            }
        }
        private static void OnVARChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.VAR = (string)e.NewValue;
                src.OnVARChg((string)e.NewValue);
            }
        }
        public virtual void OnVARChg(string des)
        {
            if (MV == null) return;
            MV.VAR = des;
        }
        #endregion

        #region ==FARBE===========
        public static readonly DependencyProperty FARBEProperty = DependencyProperty.Register("FARBE",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFARBEChanged));
        public string FARBE
        {
            get
            {
                return (string)GetValue(FARBEProperty);
            }
            set
            {
                SetValue(FARBEProperty, value);  
            }
        }
        private static void OnFARBEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.FARBE = (string)e.NewValue;
                src.OnFARBEChg();
            }
        }
        public virtual void OnFARBEChg()
        {
            if (MV == null) return;
            MV.FARBE = FARBE;
        }
        #endregion

        #region ==FINISH===========
        public static readonly DependencyProperty FINISHProperty = DependencyProperty.Register("FINISH",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFINISHChanged));
        public string FINISH
        {
            get
            {
                return (string)GetValue(FINISHProperty);
            }
            set
            {
                SetValue(FINISHProperty, value); 
            }
        }
        private static void OnFINISHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.FINISH = (string)e.NewValue;
                src.OnFINISHChg();
            }
        }
        public virtual void OnFINISHChg()
        {
            if (MV == null) return;
            MV.FINISH = FINISH;
        }
        #endregion

        #region ==DESS===========
        public static readonly DependencyProperty DESSProperty = DependencyProperty.Register("DESS",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDESSChanged));
        public string DESS
        {
            get
            {
                return (string)GetValue(DESSProperty);
            }
            set
            {
                SetValue(DESSProperty, value); 
            }
        }
        private static void OnDESSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.DESS = (string)e.NewValue;
                src.OnDESSChg();
            }
        }
        public virtual void OnDESSChg()
        {
            if (MV == null) return;
            MV.DESS = DESS;
        }
        #endregion

        #region ==PARTIE===========
        public static readonly DependencyProperty PARTIEProperty = DependencyProperty.Register("PARTIE",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPARTIEChanged));
        public string PARTIE
        {
            get
            {
                return (string)GetValue(PARTIEProperty);
            }
            set
            {
                SetValue(PARTIEProperty, value);
                OnPARTIEChg();
            }
        }
        private static void OnPARTIEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.PARTIE = (string)e.NewValue;
            }
        }
        public virtual void OnPARTIEChg()
        {
          
        }
        #endregion

        #region ==COLORIT===========
        public static readonly DependencyProperty COLORITProperty = DependencyProperty.Register("COLORIT",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCOLORITChanged));
        public string COLORIT
        {
            get
            {
                return (string)GetValue(COLORITProperty);
            }
            set
            {
                SetValue(COLORITProperty, value);
                OnCOLORITChg();
            }
        }
        private static void OnCOLORITChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.COLORIT = (string)e.NewValue;
            }
        }
        public virtual void OnCOLORITChg()
        {
            if (MV == null) return;
            MV.COLORIT = COLORIT;
        }
        #endregion

        #region ==FSIZE===========
        public static readonly DependencyProperty FSIZEProperty = DependencyProperty.Register("FSIZE",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFSIZEChanged));
        public string FSIZE
        {
            get
            {
                return (string)GetValue(FSIZEProperty);
            }
            set
            {
                SetValue(FSIZEProperty, value);
                OnFSIZEChg();
            }
        }
        private static void OnFSIZEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.FSIZE = (string)e.NewValue;
            }
        }
        public virtual void OnFSIZEChg()
        {
            if (MV == null) return;
            MV.FSIZE = FSIZE;
        }
        #endregion

        #region ==DES===========
        public static readonly DependencyProperty DESProperty = DependencyProperty.Register("DES",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDESChanged));
        public string DES
        {
            get
            {
                return (string)GetValue(DESProperty);
            }
            set
            {
                SetValue(DESProperty, value);
                OnDESChg(value);
                if (MV == null) return;
                MV.DES = value;
            }
        }
        private static void OnDESChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.DES = (string)e.NewValue;
            }
        }
        public virtual void OnDESChg(string des)
        { }
        #endregion

        #region ==DEFTXT===========
        public static readonly DependencyProperty DEFTXTProperty = DependencyProperty.Register("DEFTXT",
            typeof(List<string>), typeof(ViewBase),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDEFTXTChanged));
        public List<string> DEFTXT
        {
            get
            {
                return (List<string>)GetValue(DEFTXTProperty);
            }
            set
            {
                SetValue(DEFTXTProperty, value);
                if (MV == null) return;
                MV.DEFTXT = value;
            }
        }
        private static void OnDEFTXTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.DEFTXT = (List<string>)e.NewValue;
            }
        }
        #endregion

        #region ==IsMasterFromMV===========
        public static readonly DependencyProperty IsMasterFromMVProperty = DependencyProperty.Register("IsMasterFromMV",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsMasterFromMVChanged));
        public bool IsMasterFromMV
        {
            get
            {
                return (bool)GetValue(IsMasterFromMVProperty);
            }
            set
            {
                SetValue(IsMasterFromMVProperty, value);
            }
        }
        private static void OnIsMasterFromMVChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsMasterFromMV = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsPage===========
        public static readonly DependencyProperty IsPageProperty = DependencyProperty.Register("IsPage",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsPageChanged));
        public bool IsPage
        {
            get
            {
                return (bool)GetValue(IsPageProperty);
            }
            set
            {
                SetValue(IsPageProperty, value);
                if (MV == null) return;
                MV.IsPage = value;
            }
        }
        private static void OnIsPageChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsPage = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsPopUp===========
        public static readonly DependencyProperty IsPopUpProperty = DependencyProperty.Register("IsPopUp",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsPopUpChanged));
        public bool IsPopUp
        {
            get
            {
                return (bool)GetValue(IsPopUpProperty);
            }
            set
            {
                SetValue(IsPopUpProperty, value);
            }
        }
        private static void OnIsPopUpChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsPopUp = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsBusy===========
        public static readonly DependencyProperty IsBusyProperty = DependencyProperty.Register("IsBusy",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsBusyChanged));
        public bool IsBusy
        {
            get
            {
                return (bool)GetValue(IsBusyProperty);
            }
            set
            {
                SetValue(IsBusyProperty, value);
                OnBusyChg();

            }
        }
        private static void OnIsBusyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsBusy = (bool)e.NewValue;
            }
        }
        public virtual void OnBusyChg()
        {
            if (IsBusy)
            {
                if (this.father != null)
                    ((Control)this.father).IsEnabled = false;
            }
               
            else
            {
                if(this.father != null)
                     ((Control)this.father).IsEnabled = true;
            }
            if (MV == null) return;
            MV.IsBusy = IsBusy;
        }
        #endregion

        #region ==IsReload===========
        public static readonly DependencyProperty IsReloadProperty = DependencyProperty.Register("IsReload",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsReloadChanged));
        public bool IsReload
        {
            get
            {
                return (bool)GetValue(IsReloadProperty);
            }
            set
            {
                SetValue(IsReloadProperty, value);
                OnReload(value);
            }
        }
        private static void OnIsReloadChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsReload = (bool)e.NewValue;
            }
        }
        public virtual void OnReload(bool value)
        {
            IsReload = !IsReload;
        }

        #endregion

        #region ==IsSaved===========
        public static readonly DependencyProperty IsSavedProperty = DependencyProperty.Register("IsSaved",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsSavedChanged));
        public bool IsSaved
        {
            get
            {
                return (bool)GetValue(IsSavedProperty);
            }
            set
            {
                SetValue(IsSavedProperty, value);
                if (MV == null) return;
                MV.IsSaved = value; 
            }
        }
        private static void OnIsSavedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsSaved = (bool)e.NewValue;
                src.OnSave();
            }
        }
        public virtual void OnSave()
        { }

        #endregion


        public double TVHeight
        {
            get
            {
                return this.ActualHeight;
            }
            set
            {
                this.Height = value;
            }
        }
         

        #region ==IsEdit===========
        public static readonly DependencyProperty IsEditProperty = DependencyProperty.Register("IsEdit",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsEditChanged));
        public bool IsEdit
        {
            get
            {
                return (bool)GetValue(IsEditProperty);
            }
            set
            {
                SetValue(IsEditProperty, value);
                if (MV == null) return;
                MV.IsEdit = value; 
                OnEdit();
            }
        }
        private static void OnIsEditChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsEdit = (bool)e.NewValue;
            }
        }

        public virtual void OnEdit()
        {
        }
        #endregion

        #region ==IsManage===========
        public static readonly DependencyProperty IsManageProperty = DependencyProperty.Register("IsManage",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsManageChanged));
        public bool IsManage
        {
            get
            {
                return (bool)GetValue(IsManageProperty);
            }
            set
            {
                SetValue(IsManageProperty, value);
               

            }
        }
        private static void OnIsManageChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsManage = (bool)e.NewValue;
                src.OnManageChg();
            }
        }
        public virtual void OnManageChg()
        {
            if (MV == null)
                return;
            MV.IsManage = IsManage; 
            LOADALL();
        }
        #endregion

        #region ==IsNew===========
        public static readonly DependencyProperty IsNewProperty = DependencyProperty.Register("IsNew",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsNewChanged));
        public bool IsNew
        {
            get
            {
                return (bool)GetValue(IsNewProperty);
            }
            set
            {
                SetValue(IsNewProperty, value);
                OnNewChg();
                if (MV == null) return;
                MV.IsNew = value;
            }
        }
        private static void OnIsNewChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsNew = (bool)e.NewValue;
            }
        }
        public virtual void OnNewChg()
        { }
        #endregion

        #region ==IsKEY===========
        public static readonly DependencyProperty IsKEYProperty = DependencyProperty.Register("IsKEY",
            typeof(bool), typeof(ViewBase),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsKEYChanged));
        public bool IsKEY
        {
            get
            {
                return (bool)GetValue(IsKEYProperty);
            }
            set
            {
                SetValue(IsKEYProperty, value);
                if (MV == null) return;
                MV.IsKEY = value;
            }
        }
        private static void OnIsKEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.IsKEY = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==Selects===========
        public static readonly DependencyProperty SelectsProperty = DependencyProperty.Register("Selects",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSelectsChanged));
        public string Selects
        {
            get
            {
                return (string)GetValue(SelectsProperty);
            }
            set
            {
                SetValue(SelectsProperty, value);

            }
        }
        private static void OnSelectsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.Selects = (string)e.NewValue;
            }
        }
        #endregion

        #region ==SelctionKey===========
        public static readonly DependencyProperty SelctionKeyProperty = DependencyProperty.Register("SelctionKey",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSelctionKeyChanged));
        public string SelctionKey
        {
            get
            {
                return (string)GetValue(SelctionKeyProperty);
            }
            set
            {
                SetValue(SelctionKeyProperty, value);
            }
        }
        private static void OnSelctionKeyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.SelctionKey = (string)e.NewValue;
            }
        }
        #endregion

        #region ==AppMode===========
        public static readonly DependencyProperty AppModeProperty = DependencyProperty.Register("AppMode",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAppModeChanged));
        public string AppMode
        {
            get
            {
                return (string)GetValue(AppModeProperty);
            }
            set
            {
                SetValue(AppModeProperty, value);
                if (MV == null) return;
                MV.AppMode = value;
                OnAppModeChg();
            }
        }
        private static void OnAppModeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.AppMode = (string)e.NewValue;
            }
        }
        public virtual void OnAppModeChg()
        {

        }

        #endregion

        #region ==LANG===========
        public static readonly DependencyProperty LANGProperty = DependencyProperty.Register("LANG",
            typeof(string), typeof(ViewBase),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLANGChanged));
        public string LANG
        {
            get
            {
                return app.LANG;
            }
            set
            {
                SetValue(LANGProperty, value);
                OnLANGChg(value);
            }
        }
        private static void OnLANGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as ViewBase;
            if (src != null)
            {
                src.LANG = (string)e.NewValue;
            }
        }
        public virtual void OnLANGChg(string lang)
        {
            if (MV == null) return;
            MV.LANG = lang;

        }
        #endregion

        public string filter = "";

        public WrapPanel znExt
        {
            get
            {
                return (WrapPanel)this.FindName("ZoneExt");
            }
        }
        public ItemsControl master
        {
            get
            { return (ItemsControl)this.FindName("dlgMaster"); }
        }
        public BindingListCollectionView cvMaster
        {
            get
            {
                if (master == null) return null;
                return (BindingListCollectionView)CollectionViewSource.GetDefaultView(master.ItemsSource);
            }
        }

        public DataRow[] rows;
        public string sort = "";
        public DataRow dwData;
        public DataSet SResult;

        public virtual void LOADALL()
        {

        }

        public bool IsLoaded = false;

        public ViewModelBase vm;
        public ViewModelBase MV;

        public INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }

        public INTEXBL INTEXBL
        {
            get
            {

                return app.INTEXBL;
            }
        }

        public OracleConnection OracleDB
        {
            get
            {

                return app.OracleDB;
            }
        }

        public string TB
        {
            get
            {
                if (MV == null) return "";
                return MV.TableName;
            }
        }

        public DataTable TBTemp
        {
            get
            {
                if (MV == null) return null;
                return MV.TBTemp;
            }
            set
            {
                if (MV == null) return;
                MV.TBTemp = value;
            }
        }
        public DataTable TBMain
        {
            get
            {
                if (MV == null) return null;
                return MV.TBMain;
            }
            set
            {
                if (MV == null) return;
                MV.TBMain = value;
            }
        }

        public DataTable TBDetail
        {
            get
            {
                if (MV == null) return null;
                return MV.TBDetail;
            }
            set
            {
                if (MV == null) return;
                MV.TBDetail = value;
            }
        }

        public DependencyObject father = null;  
        public virtual void OnWHChg(string value)
        {
            if (value.Length < 12)
                return;
            LO = value.Substring(0, 2);
            LB = value.Substring(2, 2);
            LP = value.Substring(4, 8);
        }
    }
}
